package com.hmall.item.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 35192
 * @date 2021-08-21 14:53
 */
@Configuration // 注解要写，不然后台获取不到分页对象中的信息
public class MybatisPlusConfig {

    /**
     * 返回 MybatisPlusInterceptor 拦截器实现分页
     * @return
     */
    @Bean
    public MybatisPlusInterceptor paginationInnerInterceptor(){
// 构建MyBatis的拦截器对象
        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
// 添加分页拦截器，并指定数据库类型为MySQL
        mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
// 返回拦截器对象
        return mybatisPlusInterceptor;
    }
}